Format markdown code blocks with line-by-line regex parse#22996
Format markdown code blocks with line-by-line regex parse#22996
Conversation
Typing conformance resultsNo changes detected ✅ |
|
|
|
Performance comparison of current main (without these features) and this PR branch: Performance on this PR is faster wall-time than #22937 (~45ms vs ~54ms) while also including the skip feature, and uses half the "User" time (~160ms vs ~320ms). |
crates/ruff_markdown/src/lib.rs
Outdated
| for code_line in lines.by_ref() { | ||
| if let Some(closing_capture) = MARKDOWN_CODE_FENCE.captures(&code_line) { |
There was a problem hiding this comment.
You could maybe save some indentation by using a let-else here. Alternatively, if you're only looking for this final line, I think you could maybe do something like:
let Some(closing_capture) = lines.by_ref().find_map(|code_line| MARKDOWN_CODE_FENCE.captures(&code_line) else {
continue
}There was a problem hiding this comment.
Unfortunately it needs to be more complicated than that, because it has to keep looking at lines matching the regex until it also finds lines that meet the conditions from line 79-85, so that it's handling cases where code blocks contain embedded code blocks (eg, not Python, or cases where the code block contains Python code that contains docstrings that contain code blocks 😅).
But the let-else to remove a layer of indentation is useful.
Format markdown with line-by-line regex parse
regexcrate, so no backtracking or backreferences needed~~~and arbitrary length code fences<!-- ruff:off -->to skip formatting code blocksObviates #22962 and #22937